package com.vast.vastlcd.lcdAPI;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Extension of {@link DataInputStream} created to deal with the fact that 
 * x86 (the only currently supported host) is in LSB and Java is always 
 * in MSB.   
 */
public class LCDDataInputStream extends DataInputStream {

	/**
	 * Constructor.
	 * @param in The input stream
	 */
	public LCDDataInputStream(InputStream in) {
		super(in);		
	}

	/**
	 * Read a 4 byte Integer byte-by-byte in MSB mode into an LSB integer. 
	 * TODO: What about 64bit architecture?
	 * @return A correctly structured LSB 4 byte Integer.
	 * @throws IOException If the stream read fails.
	 */
	public int readLSBInt() throws IOException {
		int LSB_Int = 0;
		LSB_Int = super.read();
		LSB_Int += (super.read() << 8);
		LSB_Int += (super.read() << 16);
		LSB_Int += (super.read() << 24);	
		
		return LSB_Int;
	}
}
